﻿using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
using KaoQin.DBUtility;//Please add references
namespace KaoQin.DAL
{
    /// <summary>
    /// 数据访问类:SysWorkTimeParas
    /// </summary>
    public partial class SysWorkTimeParas
    {
        public SysWorkTimeParas()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from SysWorkTimeParas");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            return SQLiteHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(KaoQin.Model.SysWorkTimeParasInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into SysWorkTimeParas(");
            strSql.Append("ID,KNum,BeginStart1,BeginStop1,BeginTime1,EndTime1,EndStart1,EndStop1,BeginStart2,BeginStop2,BeginTime2,EndTime2,EndStart2,EndStop2,BeginStart3,BeginStop3,BeginTime3,EndTime3,EndStart3,EndStop3,BeginDelayTime,EndForwardTime,ProhibitNoTime,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@ID,@KNum,@BeginStart1,@BeginStop1,@BeginTime1,@EndTime1,@EndStart1,@EndStop1,@BeginStart2,@BeginStop2,@BeginTime2,@EndTime2,@EndStart2,@EndStop2,@BeginStart3,@BeginStop3,@BeginTime3,@EndTime3,@EndStart3,@EndStop3,@BeginDelayTime,@EndForwardTime,@ProhibitNoTime,@CreateTime)");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50),
					new SQLiteParameter("@KNum", DbType.String,50),
					new SQLiteParameter("@BeginStart1", DbType.DateTime),
					new SQLiteParameter("@BeginStop1", DbType.DateTime),
					new SQLiteParameter("@BeginTime1", DbType.DateTime),
					new SQLiteParameter("@EndTime1", DbType.DateTime),
					new SQLiteParameter("@EndStart1", DbType.DateTime),
					new SQLiteParameter("@EndStop1", DbType.DateTime),
					new SQLiteParameter("@BeginStart2", DbType.DateTime),
					new SQLiteParameter("@BeginStop2", DbType.DateTime),
					new SQLiteParameter("@BeginTime2", DbType.DateTime),
					new SQLiteParameter("@EndTime2", DbType.DateTime),
					new SQLiteParameter("@EndStart2", DbType.DateTime),
					new SQLiteParameter("@EndStop2", DbType.DateTime),
					new SQLiteParameter("@BeginStart3", DbType.DateTime),
					new SQLiteParameter("@BeginStop3", DbType.DateTime),
					new SQLiteParameter("@BeginTime3", DbType.DateTime),
					new SQLiteParameter("@EndTime3", DbType.DateTime),
					new SQLiteParameter("@EndStart3", DbType.DateTime),
					new SQLiteParameter("@EndStop3", DbType.DateTime),
					new SQLiteParameter("@BeginDelayTime", DbType.Int32,4),
					new SQLiteParameter("@EndForwardTime", DbType.Int32,4),
					new SQLiteParameter("@ProhibitNoTime", DbType.Int32,4),
					new SQLiteParameter("@CreateTime", DbType.DateTime)};
            parameters[0].Value = model.ID;
            parameters[1].Value = model.KNum;
            parameters[2].Value = model.BeginStart1;
            parameters[3].Value = model.BeginStop1;
            parameters[4].Value = model.BeginTime1;
            parameters[5].Value = model.EndTime1;
            parameters[6].Value = model.EndStart1;
            parameters[7].Value = model.EndStop1;
            parameters[8].Value = model.BeginStart2;
            parameters[9].Value = model.BeginStop2;
            parameters[10].Value = model.BeginTime2;
            parameters[11].Value = model.EndTime2;
            parameters[12].Value = model.EndStart2;
            parameters[13].Value = model.EndStop2;
            parameters[14].Value = model.BeginStart3;
            parameters[15].Value = model.BeginStop3;
            parameters[16].Value = model.BeginTime3;
            parameters[17].Value = model.EndTime3;
            parameters[18].Value = model.EndStart3;
            parameters[19].Value = model.EndStop3;
            parameters[20].Value = model.BeginDelayTime;
            parameters[21].Value = model.EndForwardTime;
            parameters[22].Value = model.ProhibitNoTime;
            parameters[23].Value = model.CreateTime;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(KaoQin.Model.SysWorkTimeParasInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update SysWorkTimeParas set ");
            strSql.Append("KNum=@KNum,");
            strSql.Append("BeginStart1=@BeginStart1,");
            strSql.Append("BeginStop1=@BeginStop1,");
            strSql.Append("BeginTime1=@BeginTime1,");
            strSql.Append("EndTime1=@EndTime1,");
            strSql.Append("EndStart1=@EndStart1,");
            strSql.Append("EndStop1=@EndStop1,");
            strSql.Append("BeginStart2=@BeginStart2,");
            strSql.Append("BeginStop2=@BeginStop2,");
            strSql.Append("BeginTime2=@BeginTime2,");
            strSql.Append("EndTime2=@EndTime2,");
            strSql.Append("EndStart2=@EndStart2,");
            strSql.Append("EndStop2=@EndStop2,");
            strSql.Append("BeginStart3=@BeginStart3,");
            strSql.Append("BeginStop3=@BeginStop3,");
            strSql.Append("BeginTime3=@BeginTime3,");
            strSql.Append("EndTime3=@EndTime3,");
            strSql.Append("EndStart3=@EndStart3,");
            strSql.Append("EndStop3=@EndStop3,");
            strSql.Append("BeginDelayTime=@BeginDelayTime,");
            strSql.Append("EndForwardTime=@EndForwardTime,");
            strSql.Append("ProhibitNoTime=@ProhibitNoTime,");
            strSql.Append("CreateTime=@CreateTime");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@KNum", DbType.String,50),
					new SQLiteParameter("@BeginStart1", DbType.DateTime),
					new SQLiteParameter("@BeginStop1", DbType.DateTime),
					new SQLiteParameter("@BeginTime1", DbType.DateTime),
					new SQLiteParameter("@EndTime1", DbType.DateTime),
					new SQLiteParameter("@EndStart1", DbType.DateTime),
					new SQLiteParameter("@EndStop1", DbType.DateTime),
					new SQLiteParameter("@BeginStart2", DbType.DateTime),
					new SQLiteParameter("@BeginStop2", DbType.DateTime),
					new SQLiteParameter("@BeginTime2", DbType.DateTime),
					new SQLiteParameter("@EndTime2", DbType.DateTime),
					new SQLiteParameter("@EndStart2", DbType.DateTime),
					new SQLiteParameter("@EndStop2", DbType.DateTime),
					new SQLiteParameter("@BeginStart3", DbType.DateTime),
					new SQLiteParameter("@BeginStop3", DbType.DateTime),
					new SQLiteParameter("@BeginTime3", DbType.DateTime),
					new SQLiteParameter("@EndTime3", DbType.DateTime),
					new SQLiteParameter("@EndStart3", DbType.DateTime),
					new SQLiteParameter("@EndStop3", DbType.DateTime),
					new SQLiteParameter("@BeginDelayTime", DbType.Int32,4),
					new SQLiteParameter("@EndForwardTime", DbType.Int32,4),
					new SQLiteParameter("@ProhibitNoTime", DbType.Int32,4),
					new SQLiteParameter("@CreateTime", DbType.DateTime),
					new SQLiteParameter("@ID", DbType.String,50)};
            parameters[0].Value = model.KNum;
            parameters[1].Value = model.BeginStart1;
            parameters[2].Value = model.BeginStop1;
            parameters[3].Value = model.BeginTime1;
            parameters[4].Value = model.EndTime1;
            parameters[5].Value = model.EndStart1;
            parameters[6].Value = model.EndStop1;
            parameters[7].Value = model.BeginStart2;
            parameters[8].Value = model.BeginStop2;
            parameters[9].Value = model.BeginTime2;
            parameters[10].Value = model.EndTime2;
            parameters[11].Value = model.EndStart2;
            parameters[12].Value = model.EndStop2;
            parameters[13].Value = model.BeginStart3;
            parameters[14].Value = model.BeginStop3;
            parameters[15].Value = model.BeginTime3;
            parameters[16].Value = model.EndTime3;
            parameters[17].Value = model.EndStart3;
            parameters[18].Value = model.EndStop3;
            parameters[19].Value = model.BeginDelayTime;
            parameters[20].Value = model.EndForwardTime;
            parameters[21].Value = model.ProhibitNoTime;
            parameters[22].Value = model.CreateTime;
            parameters[23].Value = model.ID;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SysWorkTimeParas ");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            int rows = SQLiteHelper.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string IDlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from SysWorkTimeParas ");
            strSql.Append(" where ID in (" + IDlist + ")  ");
            int rows = SQLiteHelper.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KaoQin.Model.SysWorkTimeParasInfo GetModel(string ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,KNum,BeginStart1,BeginStop1,BeginTime1,EndTime1,EndStart1,EndStop1,BeginStart2,BeginStop2,BeginTime2,EndTime2,EndStart2,EndStop2,BeginStart3,BeginStop3,BeginTime3,EndTime3,EndStart3,EndStop3,BeginDelayTime,EndForwardTime,ProhibitNoTime,CreateTime from SysWorkTimeParas ");
            strSql.Append(" where ID=@ID ");
            SQLiteParameter[] parameters = {
					new SQLiteParameter("@ID", DbType.String,50)			};
            parameters[0].Value = ID;

            KaoQin.Model.SysWorkTimeParasInfo model = new KaoQin.Model.SysWorkTimeParasInfo();
            DataSet ds = SQLiteHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public KaoQin.Model.SysWorkTimeParasInfo DataRowToModel(DataRow row)
        {
            KaoQin.Model.SysWorkTimeParasInfo model = new KaoQin.Model.SysWorkTimeParasInfo();
            if (row != null)
            {
                if (row["ID"] != null)
                {
                    model.ID = row["ID"].ToString();
                }
                if (row["KNum"] != null)
                {
                    model.KNum = row["KNum"].ToString();
                }
                if (row["BeginStart1"] != null && row["BeginStart1"].ToString() != "")
                {
                    model.BeginStart1 = DateTime.Parse(row["BeginStart1"].ToString());
                }
                if (row["BeginStop1"] != null && row["BeginStop1"].ToString() != "")
                {
                    model.BeginStop1 = DateTime.Parse(row["BeginStop1"].ToString());
                }
                if (row["BeginTime1"] != null && row["BeginTime1"].ToString() != "")
                {
                    model.BeginTime1 = DateTime.Parse(row["BeginTime1"].ToString());
                }
                if (row["EndTime1"] != null && row["EndTime1"].ToString() != "")
                {
                    model.EndTime1 = DateTime.Parse(row["EndTime1"].ToString());
                }
                if (row["EndStart1"] != null && row["EndStart1"].ToString() != "")
                {
                    model.EndStart1 = DateTime.Parse(row["EndStart1"].ToString());
                }
                if (row["EndStop1"] != null && row["EndStop1"].ToString() != "")
                {
                    model.EndStop1 = DateTime.Parse(row["EndStop1"].ToString());
                }
                if (row["BeginStart2"] != null && row["BeginStart2"].ToString() != "")
                {
                    model.BeginStart2 = DateTime.Parse(row["BeginStart2"].ToString());
                }
                if (row["BeginStop2"] != null && row["BeginStop2"].ToString() != "")
                {
                    model.BeginStop2 = DateTime.Parse(row["BeginStop2"].ToString());
                }
                if (row["BeginTime2"] != null && row["BeginTime2"].ToString() != "")
                {
                    model.BeginTime2 = DateTime.Parse(row["BeginTime2"].ToString());
                }
                if (row["EndTime2"] != null && row["EndTime2"].ToString() != "")
                {
                    model.EndTime2 = DateTime.Parse(row["EndTime2"].ToString());
                }
                if (row["EndStart2"] != null && row["EndStart2"].ToString() != "")
                {
                    model.EndStart2 = DateTime.Parse(row["EndStart2"].ToString());
                }
                if (row["EndStop2"] != null && row["EndStop2"].ToString() != "")
                {
                    model.EndStop2 = DateTime.Parse(row["EndStop2"].ToString());
                }
                if (row["BeginStart3"] != null && row["BeginStart3"].ToString() != "")
                {
                    model.BeginStart3 = DateTime.Parse(row["BeginStart3"].ToString());
                }
                if (row["BeginStop3"] != null && row["BeginStop3"].ToString() != "")
                {
                    model.BeginStop3 = DateTime.Parse(row["BeginStop3"].ToString());
                }
                if (row["BeginTime3"] != null && row["BeginTime3"].ToString() != "")
                {
                    model.BeginTime3 = DateTime.Parse(row["BeginTime3"].ToString());
                }
                if (row["EndTime3"] != null && row["EndTime3"].ToString() != "")
                {
                    model.EndTime3 = DateTime.Parse(row["EndTime3"].ToString());
                }
                if (row["EndStart3"] != null && row["EndStart3"].ToString() != "")
                {
                    model.EndStart3 = DateTime.Parse(row["EndStart3"].ToString());
                }
                if (row["EndStop3"] != null && row["EndStop3"].ToString() != "")
                {
                    model.EndStop3 = DateTime.Parse(row["EndStop3"].ToString());
                }
                if (row["BeginDelayTime"] != null && row["BeginDelayTime"].ToString() != "")
                {
                    model.BeginDelayTime = int.Parse(row["BeginDelayTime"].ToString());
                }
                if (row["EndForwardTime"] != null && row["EndForwardTime"].ToString() != "")
                {
                    model.EndForwardTime = int.Parse(row["EndForwardTime"].ToString());
                }
                if (row["ProhibitNoTime"] != null && row["ProhibitNoTime"].ToString() != "")
                {
                    model.ProhibitNoTime = int.Parse(row["ProhibitNoTime"].ToString());
                }
                if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ID,KNum,BeginStart1,BeginStop1,BeginTime1,EndTime1,EndStart1,EndStop1,BeginStart2,BeginStop2,BeginTime2,EndTime2,EndStart2,EndStop2,BeginStart3,BeginStop3,BeginTime3,EndTime3,EndStart3,EndStop3,BeginDelayTime,EndForwardTime,ProhibitNoTime,CreateTime ");
            strSql.Append(" FROM SysWorkTimeParas ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return SQLiteHelper.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM SysWorkTimeParas ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = SQLiteHelper.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int currentIndex, int pageSize, out int recordCount)
        {
            return SQLiteHelper.Query("SysWorkTimeParas", "*", strWhere, orderby, pageSize, currentIndex, out recordCount);
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@tblName", DbType.VarChar, 255),
                    new SQLiteParameter("@fldName", DbType.VarChar, 255),
                    new SQLiteParameter("@PageSize", DbType.Int32),
                    new SQLiteParameter("@PageIndex", DbType.Int32),
                    new SQLiteParameter("@IsReCount", DbType.bit),
                    new SQLiteParameter("@OrderType", DbType.bit),
                    new SQLiteParameter("@strWhere", DbType.VarChar,1000),
                    };
            parameters[0].Value = "SysWorkTimeParas";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

